package com.zhang.sh.controller;

import com.zhang.sh.clients.OrderServiceApi;
import com.zhang.sh.pojo.Order;
import com.zhang.sh.pojo.Result;
import com.zhang.sh.pojo.UserOrderVo;
import com.zhang.sh.pojo.UserVO;
import com.zhang.sh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    OrderServiceApi orderServiceApi;
    @Autowired
    UserService userService;

    @GetMapping("user/findUser/{username}")
    public Result getUser(@PathVariable("username") String username){
        UserVO userVo = userService.getUserVo(username);
        Result reOrderList = orderServiceApi.getOrderList(username);
        List<Order> orderListData = (List<Order>)reOrderList.getData();
        return new Result(new UserOrderVo(userVo,orderListData));
    }
}
